/*
 * @Author: 千锋爱佛僧
 * @公众号: 大前端私房菜
 * @Slogan: 千锋精品教程，好学得不像实力派！
 */
export default {
  namespaced: true,
  state() {
    return {
      goodsList: [
        { name: "商品1", price: 9999, num: 10 },
        { name: "商品2", price: 99.99, num: 1 },
        { name: "商品3", price: 9.999, num: 3 },
      ],
    };
  },
  //作用类似组件中的computed，对state数据做处理后返回新数据
  getters: {
    filterList(state) {
      return state.goodsList.filter((item) => item.price > 400);
    },
  },
  mutations: {
    addGoods(state, goodsObj) {
      state.goodsList.push(goodsObj);
    },
  },
};
